const e = sel => document.querySelector(sel)

const bindEvent = (element, eventName, callback) => {
    element.addEventListener(eventName, callback)
}

// const log = console.log.bind(console)

// 重写 log 函数在 textarea 中输出 json
var log = function() {
    const args = Array.from(arguments)
    for(let ele of args) {
        console.log(ele)
        if(typeof ele === "object") {
            ele = JSON.stringify(ele)
        }
        e('#id-text-log').value += '\n' + ele
    }
}

const dividerLog = () => {
    log('===========================================================')
}

const ensure = (condition, message) => {
    // 在条件不成立的时候, 输出 message
    if (!condition) {
        log('*** 测试失败:', message)
    } else {
        log('！！！ 测试成功')
    }
}

const ensureEqual = function(a, b, message) {
    if (a !== b) {
        log(`*** 测试失败, 
        {-${a}-} 不等于 
        {-${b}-}
        , ${message}`)
    } else {
        log('*** 测试成功 !!!')
    }
}